package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ILegalCaseContractService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.LegalCaseContractCreateValidate;
import com.mdd.admin.validate.LegalCaseContractUpdateValidate;
import com.mdd.admin.validate.LegalCaseContractSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.LegalCaseContractListedVo;
import com.mdd.admin.vo.LegalCaseContractDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/contract")
@Api(tags = "案件合同记录管理")
public class LegalCaseContractController {

    @Resource
    ILegalCaseContractService iLegalCaseContractService;

    @GetMapping("/list")
    @ApiOperation(value="案件合同记录列表")
    public AjaxResult<PageResult<LegalCaseContractListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated LegalCaseContractSearchValidate searchValidate) {
        PageResult<LegalCaseContractListedVo> list = iLegalCaseContractService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="案件合同记录详情")
    public AjaxResult<LegalCaseContractDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        LegalCaseContractDetailVo detail = iLegalCaseContractService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "案件合同记录新增")
    @PostMapping("/add")
    @ApiOperation(value="案件合同记录新增")
    public AjaxResult<Object> add(@Validated @RequestBody LegalCaseContractCreateValidate createValidate) {
        iLegalCaseContractService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "案件合同记录编辑")
    @PostMapping("/edit")
    @ApiOperation(value="案件合同记录编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody LegalCaseContractUpdateValidate updateValidate) {
        iLegalCaseContractService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "案件合同记录删除")
    @PostMapping("/del")
    @ApiOperation(value="案件合同记录删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iLegalCaseContractService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
